package com.song.tools.core.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 树形实体
 *
 * @author song tools
 * @since 2024-06-06
 */
@Data
@Accessors(chain = true)
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@Deprecated
public class TreeEntity<Child, ID extends Serializable> extends SuperEntity<ID> {
    /**
     * 名称
     */
    @TableField(value = "label")
    protected String label;

    /**
     * 父ID
     */
    @TableField(value = "parent_id")
    protected ID parentId;

    /**
     * 排序
     */
    @TableField(value = "sort_value")
    protected Integer sortValue;

    /**
     * 子集
     */
    @TableField(exist = false)
    protected List<Child> children;


    /**
     * 初始化子集
     */
    public void initChildren() {
        if (getChildren() == null) {
            this.setChildren(new ArrayList<>());
        }
    }

    public void addChildren(Child child) {
        initChildren();
        children.add(child);
    }
}
